//
//  ParserMRINFO2.java
//  TestAppletXcode
//
//  Created by Thibaud PIQUET on 10/04/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//
package src.convertisseur;

import src.convertisseur.Resume;
import java.util.*;
import java.io.*;
import java.net.URL;
import org.jdom.*;
import org.jdom.Document;

/**
 *
 * @author Thibaud PIQUET
 *
 * Version 1.1 - Ksoobrayen : Evolutions vers un fichier graphML --> Le 22 feb 2011

 */
public class ParserMRINFO2 implements Runnable {

    File ftp; // File to parse
    File fileOut; // File to create
    Reader frNode; // File Reader Node
    BufferedReader brNode; // Buffer Reader Node
    String line;
    String chaine;
    String[] res;
    int countStart = 0;
    int countAfter = 0;
    String str = "";
    // ** 
    String[] keyGraphNode = {"name", "status", "AS", "switch", "nodeType", "description"};
    String[] keyGraphEdge = {"status", "linkType", "SOURCE_AS", "DESTINATION_AS"};

    String KEY = "key";
    String DATA = "data";

    public ParserMRINFO2(File file, File fileOUT) throws IOException {
        this.ftp = file;
        this.fileOut = fileOUT;
        this.frNode = new FileReader(this.ftp);
        this.brNode = new BufferedReader(this.frNode);

        FileInputStream fis = new FileInputStream(this.ftp);
        LineNumberReader l = new LineNumberReader(new BufferedReader(new InputStreamReader(fis)));
        while ((str = l.readLine()) != null) {
            countStart = l.getLineNumber();
        }
    }

    public void run() {
        try {
            this.parseToXML();
        } catch (Exception e) {
            e.printStackTrace();
            src.convertisseur.Resume result = Resume.getInstance();
            result.add("ParserMRINFO2", "procedure run had some problems : " + e);
        }
    }

    public void parseToXML() throws IOException {

        // <graphml xmlns="http://graphml.graphdrawing.org/xmlns">
        // <graph edgedefault="undirected">

        Element graphml = new Element("graphml");
        Namespace nsGraphml = Namespace.getNamespace("http://graphml.graphdrawing.org/xmlns");
        graphml.setNamespace(nsGraphml);


        Element graph = new Element("graph");
        Attribute edgedefault = new Attribute("edgedefault", "undirected");
        graph.setAttribute(edgedefault);


        // ********************************

        Element domain = new Element("domain");
        Element information = new Element("information");
        Element topology = new Element("topology");
        Element nodes = new Element("nodes");
        Element node = new Element("node");
        Element links = new Element("links");
        Element interfacesNode = new Element("interfaces");
        Element interfaceNode = new Element("interface");
        Element ip = new Element("ip");
        org.jdom.Document document = new Document(graphml);

        src.convertisseur.Resume result = Resume.getInstance();

        try {
            line = this.brNode.readLine();

            /************************************************************ Loading default values *************************************************************/
            InputStream inDefaultValues = getClass().getResourceAsStream("/src/resources/configuration.xml");

            org.jdom.input.SAXBuilder builderConfig = new org.jdom.input.SAXBuilder();
            builderConfig.setIgnoringElementContentWhitespace(true);
            org.jdom.Document documentDefaultValues = builderConfig.build(inDefaultValues);

            Element defaultValues = documentDefaultValues.getRootElement();

            boolean defaultValue_withNode = false;

            List listOfFormats = defaultValues.getChildren();
            Iterator ilistOfFormats = listOfFormats.iterator();
            while (ilistOfFormats.hasNext()) {
                Element currentChildOfDefaultValues = (Element) ilistOfFormats.next();

                if (currentChildOfDefaultValues.toString().equals("[Element: <format/>]")) {

                    if (currentChildOfDefaultValues.getAttributeValue("name").equals("MRINFO")) {

                        List listOfDefaultValuesOfFormat = currentChildOfDefaultValues.getChildren();
                        Iterator ilistOfDefaultValuesOfFormat = listOfDefaultValuesOfFormat.iterator();
                        while (ilistOfDefaultValuesOfFormat.hasNext()) {
                            Element currentChildOfFormat = (Element) ilistOfDefaultValuesOfFormat.next();

                            if (currentChildOfFormat.toString().equals("[Element: <withNode/>]")) {
                                if (currentChildOfFormat.getText().equals("1")) {
                                    defaultValue_withNode = true;
                                } else {
                                    defaultValue_withNode = false;
                                }
                            }
                        }
                    }
                }
            }
            /*************************************************************************************************************************************************/
            Element title = new Element("title");
            Element date = new Element("date");
            Element author = new Element("author");
            Element description = new Element("description");
            Date today = new Date();
            String day = "";
            String month = "";

            title.setText(fileOut.getName());
            if (today.getDate() < 10) {
                day = "0" + today.getDate();
            } else {
                day = today.getDate() + "";
            }
            if ((today.getMonth() + 1) < 10) {
                month = "0" + (today.getMonth() + 1);
            } else {
                month = (today.getMonth() + 1) + "";
            }
            date.setText((today.getYear() + 1900) + "-" + month + "-" + day);
            author.setText("File Generator");
            description.setText("File generated by ParserTCL from this jApplet");

            information.addContent(title);
            information.addContent(date);
            information.addContent(author);
            information.addContent(description);

            String state = "newNode";
            int counterInterface = 0;
            boolean BoolNodeExists = false;
            int counterInterfaceIfNodeExists = 0;
            boolean BoolLinkExists = false;

            Vector<String> tabIdLink = new Vector<String>();    // test to see if link already exists
            // we can't proceed the same way for node because, if node already exists, we have to modify it

            /* Node */
            Element ASnode;
            Element switchNode;
            Element statusNode;
            Element NodeDescription;
            Element nodeType = new Element("nodeType");

            /* Link */
            Element link;
            Element source;
            Element target;
            Element statusLink;
            Element linkType;
            Attribute nodeData;

            int counterOfUndeclaredNode = 0;
            int counterOfUndeclaredNodeFromLink = 0;

            Vector<String> tabNodeOnlyAdded = new Vector<String>();
            Vector<String> tabNodeOnlyRead = new Vector<String>();

            Vector<String> tabIpOnlyAdded = new Vector<String>();
            Vector<String> tabIpOnlyRead = new Vector<String>();

            Vector<Vector<String>> tabNodeidipintAdded = new Vector<Vector<String>>();  // Tab of idNode, ipNode, InterfaceNode
            Vector<Vector<String>> tabNodeidipintRead = new Vector<Vector<String>>();   // Tab of idNode, ASNode

            while (line != null) {
                if (line != null) {

                    if (line.startsWith("ID")) {
                        if (state.equals("newNode")) {
                            // description node line
                            res = line.split(" ");

                            // res[0] : id node
                            // res[1] : type routeur - switch
                            // res[2] : ip
                            // res[3] : AS
                            // res[4] : link type (INTRA,INTER)
                            // res[5] : domain

                            //for(int i=0;i<res.length;i++){System.out.println("res["+i+"] : "+res[i]);}

                            node = new Element("node");
                            Attribute id = new Attribute("id", res[0]);


                            //**
                            node.addContent(Utils.getNameNode("name",res[0]));

                            statusNode = new Element(DATA);
                            nodeData = new Attribute(KEY, "status");
                            statusNode.setAttribute(nodeData);
                            statusNode.setText("UP");
                            //**

                            //statusNode = new Element("status");
                            //statusNode.setText("UP");

                            //switchNode = new Element("switch");
                            //**
                            switchNode = new Element(DATA);
                            nodeData = new Attribute(KEY, "switch");
                            switchNode.setAttribute(nodeData);
                            //**

                            if (res[1].equals("SWITCH")) {
                                switchNode.setText("true");
                            } else {
                                switchNode.setText("false");
                            }

                            node.setAttribute(id);


                            //**
                            NodeDescription = new Element(DATA);
                            nodeData = new Attribute(KEY, "description");
                            NodeDescription.setAttribute(nodeData);
                            Attribute label = new Attribute("label", res[2].replace(",", ""));
                            NodeDescription.setAttribute(label);

                            //**

                            //NodeDescription = new Element("description");
                            //Attribute label = new Attribute("label",res[2].replace(",",""));

                            //NodeDescription.setAttribute(label);
                            node.addContent(NodeDescription);

                            node.addContent(statusNode);
                            String as = res[3].replace("AS", "");
                            if (!as.contains("?")) {
                                //ASnode = new Element("AS");
                                //ASnode.setText(as);
                                //node.addContent(ASnode);
                                //**
                                ASnode = new Element(DATA);
                                nodeData = new Attribute(KEY, "AS");
                                ASnode.setAttribute(nodeData);
                                ASnode.setText(as);
                                node.addContent(ASnode);
                                //**

                            }
                            node.addContent(switchNode);
                            interfacesNode = new Element("interfaces");

                            state = "interfaces";

                            nodeType = new Element("nodeType");
                            Attribute type3 = new Attribute("type3", res[4]);
                            nodeType.setAttribute(type3);

                        } else if (state.equals("interfaces")) {
                            if (interfacesNode.getChildren().isEmpty() == false) {
                                node.addContent(interfacesNode);
                            }
                            if (nodeType.getAttributes().isEmpty() == false) {
                                node.addContent(nodeType);
                            }
                            tabNodeOnlyAdded.add(node.getAttributeValue("id"));
                            nodes.addContent(node);
                            state = "newNode";
                            counterInterfaceIfNodeExists = 0;
                            BoolNodeExists = false;
                            counterInterface = 0;

                            res = line.split(" ");
                            // res[0] : id node
                            // res[1] : type routeur - switch
                            // res[2] : ip
                            // res[3] : AS
                            // res[4] : node type (INTRA,INTER)
                            // res[5] : domain

                            node = new Element("node");
                            Attribute id = new Attribute("id", res[0]);

                           // **
                            node.addContent(Utils.getNameNode("name", res[0]));

                            //**
                            statusNode = new Element(DATA);
                            nodeData = new Attribute(KEY, "status");
                            statusNode.setAttribute(nodeData);
                            statusNode.setText("UP");
                            //**

                            //statusNode = new Element("status");
                            //statusNode.setText("UP");

                            //**
                            switchNode = new Element(DATA);
                            nodeData = new Attribute(KEY, "switch");
                            switchNode.setAttribute(nodeData);
                            //**

                            //switchNode = new Element("switch");
                            if (res[1].equals("SWITCH")) {
                                switchNode.setText("true");
                            } else {
                                switchNode.setText("false");
                            }

                            node.setAttribute(id);

                            //**
                            NodeDescription = new Element(DATA);
                            nodeData = new Attribute(KEY, "description");
                            NodeDescription.setAttribute(nodeData);
                            Attribute label = new Attribute("label", res[2].replace(",", ""));
                            NodeDescription.setAttribute(label);

                            //**
                            //NodeDescription = new Element("description");
                            //Attribute label = new Attribute("label",res[2].replace(",",""));
                            //NodeDescription.setAttribute(label);
                            //node.addContent(NodeDescription);

                            node.addContent(statusNode);
                            String as = res[3].replace("AS", "");
                            if (!as.contains("?")) {
                                //ASnode = new Element("AS");
                                //ASnode.setText(as);
                                //node.addContent(ASnode);
                                //**
                                ASnode = new Element(DATA);
                                nodeData = new Attribute(KEY, "AS");
                                ASnode.setAttribute(nodeData);
                                ASnode.setText(as);
                                node.addContent(ASnode);
                                //**

                            }
                            node.addContent(switchNode);
                            interfacesNode = new Element("interfaces");

                            state = "interfaces";

                            //**
                            nodeType = new Element(DATA);
                            nodeData = new Attribute(KEY, "nodeType");
                            nodeType.setAttribute(nodeData);
                            Attribute type3 = new Attribute("type3", res[4]);
                            nodeType.setAttribute(type3);

                            //**

                            //nodeType = new Element("nodeType");
                            //Attribute type3 = new Attribute("type3",res[4]);
                            //nodeType.setAttribute(type3);
                        }
                    } else if (line.contains("->")) {
                        if (state.equals("interfaces")) {
                            res = line.split(" ");
                            // case ROUTER
                            // case interface switch
                            // res[0] :
                            // res[1] : SWITCH
                            // res[2] : ipAddress(AS)
                            // res[3] :
                            // res[4] : ->
                            // res[5] :
                            // res[6] : (AS)
                            // res[7] :
                            // res[8] : id target
                            // res[9] : AS target
                            // res[10] : (
                            // res[11] : domain source or ->
                            // res[12] : -> or )
                            // res[13] : domain target) or )
                            // res[14] : don't exist or )

                            // case interface routeur
                            // res[0] :
                            // res[1] : GLOBAL
                            // res[2] : ipAddress(AS)
                            // res[3] :
                            // res[4] : ->
                            // res[5] : ip address target
                            // res[6] : AS target
                            // res[7] :
                            // res[8] : id target
                            // res[9] : AS target
                            // res[10] : (
                            // res[11] : -> or domain source
                            // res[12] : domain target) or -> or )
                            // res[13] : ) or domain target)
                            // res[14] : don't exist or )


                            // case SWITCH
                            // res[0] :
                            // res[1] :
                            // res[2] : ()
                            // res[3] :
                            // res[4] : ->
                            // res[5] : ip address target
                            // res[6] : (AS)
                            // res[7] :
                            // res[8] : id target
                            // res[9] : AS target
                            // res[10] : (
                            // res[11] : -> or domain source or blank
                            // res[12] : domain target or -> or )
                            // res[13] : domain target) or )
                            // res[14] : don't exist or )

                            interfaceNode = new Element("interface");
                            if (BoolNodeExists == true) {
                                interfaceNode.setAttribute("id", counterInterfaceIfNodeExists + "");
                                counterInterfaceIfNodeExists++;
                            } else {
                                interfaceNode.setAttribute("id", counterInterface + "");
                            }

                            ip = new Element("ip");

                            if (res[1].contains("SWITCH")) {
                                ip.setAttribute("toSwitch", "true");

                                String res2[] = res[2].split("AS");
                                ip.setText(res2[0].replace("(", ""));
                                //System.out.println("res2[0] : "+res2[0].replace("(", ""));
                            } else if (res[1].contains("GLOBAL")) {
                                if (res.length > 12) {
                                    //System.out.println("res[12]="+res[12]+"  res[13]="+res[13]);
                                    if (res[13].equals(")") && (!res[12].equals(")") || !res[12].equals("->"))) {
                                        ip.setAttribute("domain", res[12].replace(")", ""));
                                    } else if (res[13].equals(")") || res[13].contains("->") || res[13].contains("-&gt;")) {
                                        // do nothing
                                    } else {
                                        ip.setAttribute("domain", res[13].replace(")", ""));
                                    }
                                }
                                String res2[] = res[2].split("AS");
                                ip.setText(res2[0].replace("(", ""));
                            } else if (res[2].contains("()")) {
                                if (res.length > 12) {
                                    if (res[13].equals(")")) {
                                        if (res[12].equals(")") || res[12].equals("->")) {
                                            // do nothing
                                        } else {
                                            ip.setAttribute("domain", res[12].replace(")", ""));
                                        }
                                    } else if (res[13].equals(")") || res[13].equals("-&gt;")) {
                                    } else if (!res[13].equals(")") || !res[13].equals("-&gt;")) {
                                        ip.setAttribute("domain", res[13].replace(")", ""));
                                    }
                                }
                            }

                            if (!ip.getAttributes().isEmpty() == true && !ip.getText().equals("")) {
                                interfaceNode.addContent(ip);

                                /* Adding to tabs for check */
                                Vector<String> myNodeTab = new Vector<String>();
                                myNodeTab.add(node.getAttributeValue("id"));
                                myNodeTab.add(ip.getText());
                                myNodeTab.add(interfaceNode.getAttributeValue("id"));
                                tabNodeidipintAdded.add(myNodeTab);
                            }
                            interfacesNode.addContent(interfaceNode);
                            counterInterface++;


                            /* Links */

                            BoolLinkExists = false;

                            if (res[1].contains("SWITCH") || res[1].contains("GLOBAL")) {
                                String res2[] = res[2].split("AS");
                                if (res[1].contains("SWITCH")) {
                                    if (tabIdLink.contains(res2[0].replace("(", "") + "-" + res[8])) {
                                        BoolLinkExists = true;
                                        result.add("ParserMRINFO", "Link " + res2[0].replace("(", "") + "-" + res[8] + " had 2 entries, 1 has been deleted");
                                    }
                                } else if (res[1].contains("GLOBAL")) {
                                    if (tabIdLink.contains(res2[0].replace("(", "") + "-" + res[5])) {
                                        BoolLinkExists = true;
                                        result.add("ParserMRINFO", "Link " + res2[0].replace("(", "") + "-" + res[5] + " had 2 entries, 1 has been deleted");
                                    }
                                }
                            } else if (res[2].contains("()")) {

                                //**************************
                                String label = getDescriptionLabel(node);
                                //************************
                                if (tabIdLink.contains(label + "-" + res[5])) {
                                    BoolLinkExists = true;
                                    result.add("ParserMRINFO", "Link " + label + "-" + res[5] + " had 2 entries, 1 has been deleted");
                                }

                            }

                            if (BoolLinkExists == false) {
                                //link = new Element("link");
                                //**
                                link = new Element("edge");
                                //**

                                if (res[1].contains("SWITCH") || res[1].contains("GLOBAL")) {
                                    String res2[] = res[2].split("AS");
                                    if (res[1].contains("SWITCH")) {
                                        Attribute idLink = new Attribute("id", res2[0].replace("(", "") + "-" + res[8]);
                                        tabIdLink.add(res2[0].replace("(", "") + "-" + res[8]);
                                        link.setAttribute(idLink);
                                        tabIpOnlyAdded.add(res2[0].replace("(", ""));
                                        
                                    } else if (res[1].contains("GLOBAL")) {
                                        Attribute idLink = new Attribute("id", res2[0].replace("(", "") + "-" + res[5]);
                                        tabIdLink.add(res2[0].replace("(", "") + "-" + res[5]);
                                        link.setAttribute(idLink);
                                        tabIpOnlyAdded.add(res2[0].replace("(", ""));
                                        
                                    }
                                } else if (res[2].contains("()")) {
                                        //String[] res2 = node.getChild("description").getAttributeValue("label").split("/");
                                        String label = getDescriptionLabel(node);
                                        String[] res2 = label.split("/");
                                        Attribute idLink = new Attribute("id", res2[0] + "-" + res[5]);
                                        tabIdLink.add(label + "-" + res[5]);
                                        link.setAttribute(idLink);
                                        tabIpOnlyAdded.add(res2[0]);
;

                                }

                                //source = new Element("source");
                                Attribute srcNode = new Attribute("source", node.getAttributeValue("id"));

                                //target = new Element("target");
                                Attribute tgtNode = new Attribute("target", res[8]);

                                /* Adding to tabs for check */
                                Vector<String> myNodeTab = new Vector<String>();
                                myNodeTab.add(res[8]);
                                myNodeTab.add(res[9]);
                                //myNodeTab.add(ip.getText());
                                //myNodeTab.add(interfaceNode.getAttributeValue("id"));
                                tabNodeidipintRead.add(myNodeTab);
                                tabNodeOnlyRead.add(res[8]);

                                /***********************************/
                                statusLink = Utils.getNameNode("status", "UP");
                                linkType = Utils.getNameNode("linkType", "duplex");


                                link.setAttribute(srcNode);
                                List listOfChildOfNode = node.getChildren();
                                Iterator ilistOfChildOfNode = listOfChildOfNode.iterator();
                                while (ilistOfChildOfNode.hasNext()) {
                                    Element currentNodeChild = (Element) ilistOfChildOfNode.next();

                                    if (currentNodeChild.toString().equals("[Element: <AS/>]")) {
                                        Element asLink =  Utils.getNameNode("SOURCE_AS", node.getChildText("AS"));
                                        link.addContent(asLink);
                                    }
                                }

                                /* Attempt to define interfaces used for the link
                                String tgtInterf = "";
                                List listOfChildOfNodeInterfaces = node.getChildren();
                                Iterator ilistOfChildOfNodeInterfaces = listOfChildOfNodeInterfaces.iterator();
                                while(ilistOfChildOfNodeInterfaces.hasNext()){
                                Element currentNodeChild = (Element)ilistOfChildOfNodeInterfaces.next();

                                if(currentNodeChild.toString().equals("[Element: <interfaces/>]")){
                                List listOfChildOfNodeInterface = node.getChildren();
                                Iterator ilistOfChildOfNodeInterface = listOfChildOfNodeInterface.iterator();
                                while(ilistOfChildOfNodeInterface.hasNext()){
                                Element currentInterface = (Element)ilistOfChildOfNodeInterface.next();

                                List listOfip = currentInterface.getChildren();
                                Iterator ilistOfip = listOfip.iterator();
                                while(ilistOfip.hasNext()){
                                Element currentIp = (Element)ilistOfip.next();

                                if(currentIp.toString().equals("[Element: <ip/>]")){
                                if(currentIp.getText().equals(res[5])){
                                tgtInterf=currentInterface.getAttributeValue("id");
                                System.out.println("Id interface : "+tgtInterf);
                                }
                                }
                                }
                                }
                                }
                                }

                                if(!tgtInterf.equals("")){
                                Attribute tgtInterface = new Attribute("interface",tgtInterf);
                                target.setAttribute(tgtInterface);
                                }
                                 */

                                link.setAttribute(tgtNode);
                                if (!res[9].contains("?")) {
                                    Element atLink =  Utils.getNameNode("DESTINATION_AS", res[9].replace("AS", ""));
                                    link.addContent(atLink);
                                }

                                //link.addContent(source);
                                //link.addContent(target);
                                link.addContent(statusLink);

                                link.addContent(linkType);

                                links.addContent(link);
                            }

                        }
                    }

                    if (countAfter + 1 == countStart) {
                        if (interfacesNode.getChildren().isEmpty() == false) {
                            node.addContent(interfacesNode);
                        }
                        if (!nodeType.getText().equals("")) {
                            node.addContent(nodeType);
                        }
                        tabNodeOnlyAdded.add(node.getAttributeValue("id"));
                        nodes.addContent(node);
                    }


                }
                line = this.brNode.readLine();
                countAfter++;

            }
            brNode.close();
            frNode.close();

            if (defaultValue_withNode == true) {

                /* case if undeclared node are added */
                for (int i = 0; i < tabNodeOnlyRead.size(); i++) {
                    if (!tabNodeOnlyAdded.contains(tabNodeOnlyRead.get(i))) {
                        node = new Element("node");
                        node.setAttribute("id", tabNodeOnlyRead.get(i));
                        //**
                        node.addContent(Utils.getNameNode("name",tabNodeOnlyRead.get(i)));
                        switchNode = new Element("switch");
                        switchNode.setText("false");
                        node.addContent(switchNode);
                        nodes.addContent(node);
                        tabNodeOnlyAdded.add(tabNodeOnlyRead.get(i));
                        counterOfUndeclaredNode++;
                    }
                }
            } else if (defaultValue_withNode == false) {

                /* case if undeclared node are delete from links */
                Vector<Element> tabLinkToRemove = new Vector<Element>();

                for (int i = 0; i < tabNodeOnlyRead.size(); i++) {
                    if (!tabNodeOnlyAdded.contains(tabNodeOnlyRead.get(i))) {

                        List listOfLink = links.getChildren();
                        Iterator ilistOfLink = listOfLink.iterator();
                        while (ilistOfLink.hasNext()) {
                            Element currentLink = (Element) ilistOfLink.next();

                            if (currentLink.getChild("target").getAttributeValue("node").equals(tabNodeOnlyRead.get(i))) {
                                tabLinkToRemove.add(currentLink); // we add link to remove to the tab tabLinkToRemove
                                counterOfUndeclaredNodeFromLink++;
                            }
                        }
                    }
                }

                /* Foreach link of tabLinkToRemove, we remove it from links*/
                for (int i = 0; i < tabLinkToRemove.size(); i++) {
                    links.removeContent(tabLinkToRemove.get(i));
                }
            }

            //** on cree les description
            for (int i = 0; i < keyGraphNode.length; i++) {
                topology.addContent(Utils.getKeyGraph(i, keyGraphNode, "node"));

            }

            for (int i = 0; i < keyGraphEdge.length; i++) {
                topology.addContent(Utils.getKeyGraph(i, keyGraphEdge, "edge"));

            }



            //**

            topology.addContent(nodes);
            topology.addContent(links);

            domain.addContent(information);
            domain.addContent(topology);


            // *****************
            graph.addContent(domain);
            graphml.addContent(graph);
            // ***********************

            org.jdom.output.XMLOutputter sortie = new org.jdom.output.XMLOutputter(org.jdom.output.Format.getPrettyFormat());
            sortie.output(document, new FileOutputStream(fileOut.getAbsolutePath()));

            System.gc();

            result.add("ParserMRINFO2", "Import succeeded");
            if (defaultValue_withNode == true) {
                result.add("ParserMRINFO2", counterOfUndeclaredNode + " nodes added");
            }
            if (defaultValue_withNode == false) {
                result.add("ParserMRINFO2", counterOfUndeclaredNodeFromLink + " links removed");
            }

        } catch (Exception e) {
            e.printStackTrace();
            result.add("ParserMRINFO2", "Import had problems " + e);
        }
    }

    

    private String getDescriptionLabel(Element node) {
        String label = "";
        List listedata = node.getChildren(DATA);
        Element data;
        for (int i = 0; i < listedata.size(); i++) {
            data = (Element) listedata.get(i);
            if ("description".equalsIgnoreCase(data.getAttributeValue(KEY))) {
                label = data.getAttributeValue("label");
                System.out.println("1 Label = " + data.getAttributeValue("label"));
            }
        }
        return label;
    }

   
}
